package com.request; /**
 * @author wzm
 * @create 2023-03-06 9:22
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/demoServlet")
public class DemoServlet extends HttpServlet {
    //get请求执行的方法
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //request 获取请求的数据   http://localhost:8080/项目名/demoServlet?username=zs
        String username = request.getParameter("username");
        System.out.println("username = " + username);


        //response 设置响应数据
        //通过响应头设置相应的数据类型 和编码
        response.setHeader("content-type","text/html;charset=utf-8");
        response.getWriter().write("<h1>"+username+"欢迎你</h1>");


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
